package com.wn.ticket.service.impl;

import com.wn.ticket.entity.Artist;
import com.wn.ticket.entity.User;
import com.wn.ticket.mapper.ArtistMapper;
import com.wn.ticket.mapper.UserArtistMapper;
import com.wn.ticket.service.UserArtistService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 关注Service实现
 *
 * @author 杜昭进
 * date: 2022/8/29
 */
@Slf4j
@Service
public class UserArtistServiceImpl implements UserArtistService {

    @Autowired
    private UserArtistMapper userArtistMapper;

    @Autowired
    private ArtistMapper artistMapper;

    /**
     * 关注 增加
     *
     * @param userId
     * @param artistId
     */
    @Override
    public void add(int userId, int artistId) {
        log.debug("userId:{}", userId);
        log.debug("artistId:{}", artistId);
        //粉丝数量+1
        Artist artist=new Artist();
        artist.setId(artistId);

        artist.setFans(artistMapper.getById(artistId).getFans()+1);//粉丝数+1
        artistMapper.update(artist);
        userArtistMapper.userArtistInsert(userId, artistId);
    }

    /**
     * 关注 删除
     *
     * @param userId
     * @param artistId
     */
    @Override
    public void deleted(int userId, int artistId) {
        userArtistMapper.userArtistDeleted(userId, artistId);
    }

    /**
     * 根据用户id查询所有关注艺人
     *
     * @return
     */
    @Override
    public List<User> getAllByUserId(int userId) {
        return userArtistMapper.getByUserId(userId);
    }

    @Override
    public List<User> getNamesByUserId(int userId) {
        return userArtistMapper.getNamesByUserId(userId);
    }
}
